package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao implements BaseStudentDao {
        private Student[] students = new Student[5];

        public boolean addStudent(Student student) {
        int index = -1;
        for (int i = 0; i < students.length; i++) {
            if (students[i] == null){
                index = i;
                break;
            }
        }
        if (index == -1){
            return false;
        }else{
            students[index] = student;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return students;
    }

    public void deleteById(String id) {
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && students[i].getId().equals(id)){
                students[i] = null;
            }
        }
    }

    public void updateStudent(Student student) {
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && students[i].getId().equals(student.getId())){
                students[i] = student;
            }
        }
    }
}
